package com.xyj.week05;

import com.xyj.common.TreeNode;

/**
 * 翻转二叉树 leetcode226
 */
public class T2 {


    public static TreeNode reserve(TreeNode root) {
        if (root==null) {
            return null;
        }
        // 左节点和右节点交换
        TreeNode temp = root.right;
        root.right=root.left;
        root.left=temp;
        // 子节点也这样交换
        reserve(root.left);
        reserve(root.right);
        return root;
    }
}
